

from record import Record
from singleton import singleton


@singleton
class TotalDataManager:
    def __init__(self):
        self.total_data = {}
        self.curr_record : Record = None

    def new_record(self, room_id):
        if room_id not in self.total_data:
            self.total_data[room_id] = Record(room_id)
        self.curr_record = self.total_data[room_id]
        return self.curr_record

    def add_data(self, data):
        if self.curr_record is not None:
            self.curr_record.add_data(data)
        else:
            print("No record to add data")
    
    def delete_record(self, room_id):
        if room_id in self.total_data:
            self.curr_record = None
            del self.total_data[room_id]
        else:
            print("No record to delete")
    
    def get_record(self, room_id):
        if room_id in self.total_data:
            return self.total_data[room_id]
        else:   
            return  None

global_total_data_manager = TotalDataManager()